package stu.day9_day18;

import java.util.Comparator;
import java.util.PriorityQueue;

public class LeetCode215 {
    public int findKthLargest(int[] nums, int k) {

        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });

        for(int i : nums){
            if(queue.size()<k){
                queue.offer(i);
            }else {
                if(queue.peek()<=i){
                    queue.poll();
                    queue.offer(i);
                }
            }
        }

        return queue.peek();

    }
}
